<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <link href="../static/resources/bootstrap/css/bootstrap.css" rel="stylesheet">
    <link href="../static/resources/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="../static/resources/css/style.css" rel="stylesheet">
    <link href="../static/resources/css/exam.css" rel="stylesheet">

    <script type="text/javascript" src="../static/resources/js/jquery/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="../static/resources/vue/vue.js"></script>
    <script type="text/javascript" src="../static/resources/vue/date.js"></script>
    <script type="text/javascript" src="../static/resources/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../static/resources/js/all.js"></script>
    <script type="text/javascript" src="../static/resources/js/tag-list.js"></script>
    <script type="text/javascript" src="../static/resources/js/add-tag.js"></script>
    <script type="text/javascript" src="../static/resources/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script type="text/javascript" src="../static/resources/laypage/laypage.js" charset="utf-8"></script>
    <script type="text/javascript" src="../static/resources/layui/layui.all.js" charset="utf-8"></script>
    <script type="text/javascript" src="../static/resources/bootstrap/js/bootstrapValidator.min.js"></script>
    <link href="../static/resources/bootstrap/css/bootstrapValidator.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
    <form id="editForm">
        <input type="hidden" name="tagId" id="newsId" value="${data.newsId}"/>
        <br/>
        <div class="form-group">
            <label for="title">公告名：</label> <input type="text"
                                                   class="memo" id="title" name="title" placeholder="输入公告名"
                                                   value="${data.title}">
        </div>
        <div class="form-group">
            <label for="content">事件：</label> <input type="textarea"
                                                    class="form-control" id="content" name="content"
                                                    placeholder="输入事件 &nbsp;&nbsp;&nbsp; (不能超过50字)" value="${data.content}">
        </div>


        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">提交</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
</body>
</html>
<script>

    var updateNews = function () {


    $.ajax({
        type : 'POST',
        dataType : 'json',
        url : '/updNews',
        data : {
            newsId: $("#newsId").val(),
            title: $("#title").val(),
            content: $("#content").val()
        }, success : function(data) {
            if (data>0){
                $("#cancelBtn").click();

            }

        }
    });
    };

    $("#saveBtn").click(function () {
        $("#editForm").bootstrapValidator('validate');//提交验证
        if ($("#editForm").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码
         updateNews();
        }
    });


    $('#editForm').bootstrapValidator({
        live: 'enabled',//验证时机，enabled是内容有变化就验证（默认），disabled和submitted是提交再验证
        excluded: [':disabled', ':hidden', ':not(:visible)'],//排除无需验证的控件，比如被禁用的或者被隐藏的
        submitButtons: '#saveBtn',//指定提交按钮，如果验证失败则变成disabled
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            title: {
                validators: {
                    notEmpty: {//检测非空,radio也可用
                        message: '必须输入标签名'
                    },
                    stringLength: {//检测长度
                        min: 2,
                        max: 20,
                        message: '长度必须在2-20之间'
                    },

                }
            },
            content: {
                validators: {
                    notEmpty: {//检测非空,radio也可用
                        message: '必须输入描述'
                    },
                    stringLength: {//检测长度

                        max: 50,
                        message: '长度必须在小于50'
                    }

                }
            }
        }
    });

    $("#cancelBtn").click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.getNewsPageList();
        parent.layer.close(index);

    });


</script>